
function TimeObj(day,month,year,hour,min,sec)
{
	var thisTimeObj = this;
	
	thisTimeObj.day = day;
	thisTimeObj.month = month;
	thisTimeObj.year = year;
	thisTimeObj.hour = hour;
	thisTimeObj.min = min;
	thisTimeObj.sec = sec;
	
	thisTimeObj.getStringProperties = function()
	{
	
		if(thisTimeObj.hour < 10)
		{
			thisTimeObj.hour_String = "0" + thisTimeObj.hour.toString();
		}
		else
		{
			thisTimeObj.hour_String = thisTimeObj.hour.toString();
		}
		
		if(thisTimeObj.min < 10)
		{
			thisTimeObj.min_String = "0" + thisTimeObj.min.toString();
		}
		else
		{
			thisTimeObj.min_String = thisTimeObj.min.toString();
		}
		
		if(thisTimeObj.sec < 10)
		{
			thisTimeObj.sec_String = "0" + thisTimeObj.sec.toString();
		}
		else
		{
			thisTimeObj.sec_String = thisTimeObj.sec.toString();
		}
	}

	thisTimeObj.outputDate = function()
	{
		return thisTimeObj.day + "/" + thisTimeObj.month + "/" + thisTimeObj.year;
	};
	
	thisTimeObj.outputTime =  function()
	{
		thisTimeObj.getStringProperties();
		return thisTimeObj.hour_String + ":" +	thisTimeObj.min_String + ":" + thisTimeObj.sec_String;
	};
	
	thisTimeObj.outputDateTime = function()
	{
		return thisTimeObj.outputDate() + " " + thisTimeObj.outputTime();
	};
	
	thisTimeObj.getDate = function(datetime)
	{
		thisTimeObj.year = datetime.substring(0,4);
		thisTimeObj.month = datetime.substring(5,7);
		thisTimeObj.day = datetime.substring(8,10);
		thisTimeObj.hour = datetime.substring(14,16);
		thisTimeObj.min = datetime.substring(17,19);
	};
	
	thisTimeObj.getTime = function(jsDate)
	{
		if(typeof jsDate == "object")
		{
			thisTimeObj.hour = jsDate.getHours();
			thisTimeObj.min = jsDate.getMinutes();
			thisTimeObj.sec = jsDate.getSeconds();
		}
		
		if(typeof jsDate == "string")
		{
			thisTimeObj.hour = parseInt(jsDate.substring(0,2));
			thisTimeObj.min = parseInt(jsDate.substring(2,4));
			thisTimeObj.sec = parseInt(jsDate.substring(4,6));
		}
	};
}

function Clock()
{
	var thisClock = this;
	
	thisClock.currentTime = new TimeObj(0,0,0,0,0);
	thisClock.cycleInterval = 0;
	
	thisClock.startCycle = function(interval,callback)
	{
		thisClock.callback = callback;
		thisClock.cycleInterval = interval;
		thisClock.clockTick = setInterval(function()
		{
			thisClock.clockTickAction();
		},thisClock.cycleInterval);
		thisClock.clockTickAction();
	}
	
	thisClock.clockTickAction = function()
	{
		var time = new Date();
		// thisClock.currentTime = time;
		thisClock.currentTime.getTime(time);
		thisClock.callback();
	}
}

function Alarm()
{
	var thisAlarm = this;
	thisAlarm.alarmTime = new TimeObj(0,0,0,0,0);
	thisAlarm.curTime = 0;
	thisAlarm.alarmCycle = 0;
	thisAlarm.tickInterval = 1000;
	
	thisAlarm.createAlarm = function(curTime,strTime,callback)
	{
		thisAlarm.curTime = curTime;
		thisAlarm.alarmTime.getTime(strTime);
		thisAlarm.callback = callback;
		thisAlarm.beginAlarmCycle();
	}
	
	thisAlarm.beginAlarmCycle = function () 
	{
		thisAlarm.tick = setInterval(function()
		{
			thisAlarm.tickAction();
		},thisAlarm.tickInterval);
	}
	
	thisAlarm.tickAction = function()
	{
		if((thisAlarm.alarmTime.outputTime()) == (thisAlarm.curTime.outputTime()))
		{
			thisAlarm.callback(thisAlarm);
		}
	}
}
